from django.conf.urls import url
from rest_framework.routers import SimpleRouter, DefaultRouter

from . import a1_views, \
    a2_apiview_views, \
    a3_genericapiview_views, \
    a4_mixin_views, \
    a5_child_mixin_views, \
    a6_viewset_views, \
    a7_genericviewset_views, \
    a8_modelviewset_views

urlpatterns = [
    # # view
    # url(r'^book/(?P<pk>\d+)/$', views.BookView.as_view()),
    # url(r'^books/$', views.BooksView.as_view())

    # # apiview
    # url(r'^book/(?P<pk>\d+)/$', apiview_views.BookView.as_view()),
    # url(r'^books/$', apiview_views.BooksView.as_view())

    # # genericaipview
    # url(r'^book/(?P<pk>\d+)/$', genericapiview_view.BookView.as_view()),
    # url(r'^books/$', genericapiview_view.BooksView.as_view())

    # # mixin_view
    # url(r'^book/(?P<pk>\d+)/$', mixin_view.BookView.as_view()),
    # url(r'^books/$', mixin_view.BooksView.as_view())

    # # child_mixin_view
    # url(r'^book/(?P<pk>\d+)/$', child_mixin_view.BookView.as_view()),
    # url(r'^books/$', child_mixin_view.BooksView.as_view())

    # # viewset_view
    # url(r'^book/(?P<pk>\d+)/del_one/$', a6_viewset_views.BookView.as_view({'get': 'retrieve', 'put': 'update', 'delete': 'del_one'})),
    # url(r'^books/$', a6_viewset_views.BooksView.as_view({'get': 'list', 'post': 'create'}))
]

# 自动生成路由
# routers = SimpleRouter()
routers = DefaultRouter()  # 继承自SimpleRouter，和父类的区别是当访问根路径127.0.0.1:8000/时候，如果没有自定义网页SimpleRouter会返回404, DefaultRouter不返回404
routers.register('book_drf', a8_modelviewset_views.Books, base_name='books')  # 必须配合ModelViewSet使用，否则会报错
print(routers.urls)
urlpatterns += routers.urls
